Mod:制作一个自定义天赋

您所在的位置:网站首页 noita 天赋 Mod:制作一个自定义天赋

Mod:制作一个自定义天赋

2024-07-11 06:47| 来源: 网络整理| 查看: 265

此页面的内容需要被翻译。 你可以帮助我们来翻译此页面。至于翻译的话请遵守本Wiki的翻译准则。 模组制作导航 基础 入门 • 基础 • Lua脚本 • Data.wak • 实用工具 制作指南 音频 • 敌人 • 生物群系 • 天赋 • 法术 • 精灵表 • 材料 • 图像放射器 • 特殊行为 • CMake使用 组件/实体 组件文档 • 枚举 • 特殊标签 • 所有标签列表 Lua编程 Lua API • 实用脚本 其他信息 法术和天赋的ID • 声音事件 • 魔数(Magic Numbers)

Making a new perk is relatively simple, assuming you have gone through the Modding: Basics and have a mod directory set up.

目录 1 Create & register your perk 2 Spawning and picking up a perk 3 Checking for active perks 4 Further reading Create & register your perk Add a new file to your mod (eg. files/perk_list.lua), where you define all your custom perks by appending to the perk_list table provided by the base game, repeating this code for each perk you want to add:table.insert(perk_list, { id = "MY_CUSTOM_PERK", ui_name = "My Custom Perk Name", ui_description = "A Fancy Description", ui_icon = "data/ui_gfx/perk_icons/electricity.png", -- Change this to your own perk_icon = "data/items_gfx/perks/electricity.png", -- Change this to your own game_effect = "PROTECTION_ELECTRICITY", -- Hardcoded game effect, change or remove this usable_by_enemies = false, not_in_default_perk_pool = false, --set to true to not include it in the default perk pool func = function( entity_perk_item, entity_who_picked, item_name ) -- Any code that you want to run upon perk pickup goes here. end, } ) -- if you have more perks to add table.insert(perk_list, { id = "MY_CUSTOM_PERK_TWO", -- etc } ) Add the following line to the very beginning of your init.lua, referencing the file you just created:ModLuaFileAppend("data/scripts/perks/perk_list.lua", "mods//files/perk_list.lua") That's it! Your perk should now be included in the game.

Note:

The game_effects are generally hardcoded in-engine effects, which are not customizable via Lua. We can only string them together, or leave them out and make our own effects via custom code (or both!).

For a list of valid effects you can use, see ID#Perks or the data/scripts/perks/perk_list.lua.

Spawning and picking up a perk

If you want to load the perk via script (and not rely only on holy mountains), you can spawn & pickup the perk with the following snippet:

-- NOTE: If in init.lua, do this *after* the ModLuaFileAppend line and after -- the player has spawned, for instance in the OnPlayerSpawned callback dofile_once("data/scripts/perks/perk.lua") function OnPlayerSpawned(player_entity) -- Simply spawn the entity in world at the player's location local x, y = EntityGetTransform(player_entity) local perk = perk_spawn(x, y, "MY_CUSTOM_PERK") -- To pick up the perk instantly, you can continue: perk_pickup(perk, player_entity, EntityGetName(perk), false, false) end

Checking for active perks

The default perk_pickup() adds every picked up perk as a "run flag", with the string format of PERK_PICKED_. Thus you can use the following function for easily testing if a perk is active or not:

function has_perk(perk_id) return GameHasFlagRun("PERK_PICKED_" .. perk_id) end

Further reading You can find list of all base game perks in data/scripts/perks/perk_list.lua You can find the base implementation of perks in data/scripts/perks/perk.lua Most importantly the functions: perk_spawn() and perk_pickup()



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3